package com.xjscrm.server.aop;

import com.xjscrm.common.result.ResponseCode;
import com.xjscrm.common.result.ResponseResult;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * <p>
 * Controller Aop
 * 获取响应结果信息
 * </p>
 */
@Aspect
@Component
public class ResponseResultAop {

    private static Logger logger = LoggerFactory.getLogger(ResponseResultAop.class);

    /**
     * 切点
     */
    private static final String POINTCUT = "execution(public * com.xjscrm.server.web..*.*(..))";

    @Around(POINTCUT)
    public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
        // 执行目标方法,获得返回值
        Object result = joinPoint.proceed();
        Object responseResult = null;
        try {
            responseResult = new ResponseResult(ResponseCode.SUCCESS, null, result);
        } catch (Exception e) {
            logger.error("err:", e);
        }
        return responseResult;
    }
}
